--lua script
--处理帮派相关的操作

--#include "data\config\guild\Guild.lua" once
--#include "data\functions\Guild\GuildMainBuilding.lua" once  	--行会主殿
--#include "data\functions\Guild\GuildBoss.lua" once  			--行会BOSS
--#include "data\functions\Guild\GuildRedBag.lua" once  		--行会红包
--#include "data\functions\Guild\GuildGuard.lua" once  			--守卫行会
--#include "data\functions\Guild\GuildAdventure.lua" once  		--宝藏探险
--#include "data\functions\Guild\GuildOwnScene.lua" once  		--行会冠名地图（占领）
--[[
enum tagGuildOP
{
	gGuildNoOP				= 0,			//占位
	gUpgradeGuild			= 1,			//行会升级
	gGuildDonate			= 2,			//行会捐献
	gOpenGuildBoss			= 3,			//开启行会BOSS
	gEnterGuildBoss			= 4,			//进入行会BOSS
	gGetGuildRedBagData		= 5,			//获取全部行会红包数据
	gSendGuildRedBag		= 6,			//发红包
	gGetGuildRedBag			= 7,			//领取红包
	gGetGuildBossSts		= 8,			//请求行会BOSS状态
	gOnLeaveGuild			= 9,			//离开行会
	gOpenGuildGuard			= 10,			//开启行会BOSS
	gEnterGuildGuard		= 11,			//进入行会BOSS
	gGetGuildGuardSts		= 12,			//请求行会守卫状态
	gGuildBless				= 13,			//行会祝福
	gGetGuildActivityData	= 14,			//请求行会活动状态
	gEnterGuildAdventure	= 15,			//进入行会宝藏探险
};
--]]

function GmDoGuild( sysarg, flag, param )
	print("GmDoGuild, flag="..flag..", param="..param)
	if flag == 1 then
	elseif flag == 4 then
		OpenGuildBoss( sysarg )
	elseif flag == 5 then
		EnterGuildBoss( sysarg )
	elseif flag == 6 then
		local scendId 		= Actor.getSceneId( sysarg )
		local fubenPtr 		= Actor.getFubenPrt( sysarg )
		local fubenId		= Fuben.getFuBenId(fubenPtr) or 0
		local fubenHandle	= Fuben.getFubenHandle(fubenPtr) or 0
		local sceneName		= Fuben.getSceneNameById( sceneId )
		print("actor scene and fuben, scendId="..scendId..", fubenId="..fubenId..", fubenHandle="..fubenHandle..", sceneName="..sceneName)
	elseif flag == 7 then
		Guild.sendGuildRedBagData( sysarg )
	elseif flag == 8 then
		SendGuildRegBag( sysarg, 100, 10 )
	elseif flag == 9 then
		GetGuildRedBag( sysarg, 1 )
	elseif flag == 10 then
		if param == 0 then
			Guild.sendBackGuildRedBag( false )
		else
			Guild.sendBackGuildRedBag( true )
		end
	elseif flag == 11 then
		local guildId = Actor.getGuildId(sysarg)
		Guild.changeGuildCoin(guildId, param)
	end
end


GuildOpFuncList = {}

EventCallDispatcher.HandlerGuildOp = function (sysarg, args)
 	--print("参数："..args[1])
 	if args[1] == nil then 
 		return 
 	end   --第1个参数
 	local func = GuildOpFuncList[args[1]]
 	if func ~= nil then
 		return func(sysarg, args)
 	end
end

--行会主殿升级
GuildOpFuncList[gUpgradeGuild] = function (sysarg,args)
	UpgradeGuild( sysarg, args )
end

--行会捐献
GuildOpFuncList[gGuildDonate] = function (sysarg,args)
	GuildDonate( sysarg, args )
end


--开启行会BOSS副本
GuildOpFuncList[gOpenGuildBoss] = function (sysarg,args)
	OpenGuildBoss( sysarg )
end

--进入行会BOSS副本
GuildOpFuncList[gEnterGuildBoss] = function (sysarg,args)
	EnterGuildBoss( sysarg )
end

--发行会红包
GuildOpFuncList[gSendGuildRedBag] = function (sysarg,args)
	local allYuanBao = args[2]
	local allRedBagNum = args[3]
	SendGuildRegBag( sysarg, allYuanBao, allRedBagNum )
end


--领取行会红包
GuildOpFuncList[gGetGuildRedBag] = function (sysarg,args)
	local redbagIdx = args[2]
	GetGuildRedBag( sysarg, redbagIdx )
end

--获取行会BOSS状态
GuildOpFuncList[gGetGuildBossSts] = function (sysarg,args)
	SendGuildBossSts( sysarg )
end


--开启行会守卫副本
GuildOpFuncList[gOpenGuildGuard] = function (sysarg,args)
	OpenGuildGuard( sysarg )
end

--进入行会守卫副本
GuildOpFuncList[gEnterGuildGuard] = function (sysarg,args)
	EnterGuildGuard( sysarg )
end

--获取行会守卫状态
GuildOpFuncList[gGetGuildGuardSts] = function (sysarg,args)
	SendGuildGuardSts( sysarg )
end

--行会祝福
GuildOpFuncList[gGuildBless] = function (sysarg,args)
	GuildBless( sysarg )
end

--获取行会活动数据
GuildOpFuncList[gGetGuildActivityData] = function (sysarg,args)
	SendGuildActivityData( sysarg )
end

GuildOpFuncList[gEnterGuildAdventure] = function (sysarg,args)
	local adventureIdx = args[2]
	EnterGuildAdventure( sysarg, adventureIdx )
end


--[[
清理每日行会数据
]]
function ProcGuildDailyData(  )
	local dVar = System.getDyanmicVar()
	dVar.guildBoss 	= nil		--行会BOSS
	dVar.guildGuard = nil		--守卫行会
end

--[[
登陆（不是在线跨天）
]]
function OnGuildLoginIn( sysarg )
	ProcGuildBlessLoginIn( sysarg )
end

--[[
在线跨天（不是登陆）
]]
function OnGuildNewDay( sysarg )
	ProcGuildBlessNewDay( sysarg )
end

--[[
下发行会活动数据
]]
function SendGuildActivityData( sysarg )
	SendActorDailyOpTimesUsed( sysarg, enDailyOpTimes_GuildAdventure, 0 )				--行会宝藏探险次数
	SendActorDailyOpTimesUsed( sysarg, enDailyOpTimes_GuildFightBoss, 0 )				--行会血战BOSS次数
end

EventCallDispatcher.registerEventCall(BaseTypes.ActorEventId.aeGuild, EventCallDispatcher.HandlerGuildOp)
